home *** CD-ROM | disk | FTP | other *** search
/ Download Now 8 / Download Now V8.iso / Program / InternetTools / ApacheWebServer1.3.6 / apache_1_3_6_win32.exe / _SETUP.1 / split-logfile < prev    next >
Encoding:
Text File  |  1999-01-01  |  4.2 KB  |  104 lines

  1. #!/usr/local/bin/perl
  2. #
  3. # ====================================================================
  4. # Copyright (c) 1995-1999 The Apache Group.  All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. #
  10. # 1. Redistributions of source code must retain the above copyright
  11. #    notice, this list of conditions and the following disclaimer. 
  12. #
  13. # 2. Redistributions in binary form must reproduce the above copyright
  14. #    notice, this list of conditions and the following disclaimer in
  15. #    the documentation and/or other materials provided with the
  16. #    distribution.
  17. #
  18. # 3. All advertising materials mentioning features or use of this
  19. #    software must display the following acknowledgment:
  20. #    "This product includes software developed by the Apache Group
  21. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  22. #
  23. # 4. The names "Apache Server" and "Apache Group" must not be used to
  24. #    endorse or promote products derived from this software without
  25. #    prior written permission.  For permission please contact
  26. #    Apache@Apache.Org.
  27. #
  28. # 5. Products derived from this software may not be called "Apache"
  29. #    nor may "Apache" appear in their names without prior written
  30. #    permission of the Apache Group.
  31. #
  32. # 6. Redistributions of any form whatsoever must retain the following
  33. #    acknowledgment:
  34. #    "This product includes software developed by the Apache Group
  35. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  36. #
  37. # THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  38. # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  39. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  40. # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  41. # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  43. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  44. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  46. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  47. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  48. # OF THE POSSIBILITY OF SUCH DAMAGE.
  49. # ====================================================================
  50. #
  51. # This software consists of voluntary contributions made by many
  52. # individuals on behalf of the Apache Group and was originally based
  53. # on public domain software written at the National Center for
  54. # Supercomputing Applications, University of Illinois, Urbana-Champaign.
  55. # For more information on the Apache Group and the Apache HTTP server
  56. # project, please see <http://www.apache.org/>.
  57. #
  58.  
  59. #
  60. # This script will take a combined Web server access
  61. # log file and break its contents into separate files.
  62. # It assumes that the first field of each line is the
  63. # virtual host identity (put there by "%v"), and that
  64. # the logfiles should be named that+".log" in the current
  65. # directory.
  66. #
  67. # The combined log file is read from stdin. Records read
  68. # will be appended to any existing log files.
  69. #
  70. %is_open = ();
  71.  
  72. while ($log_line = <STDIN>) {
  73.     #
  74.     # Get the first token from the log record; it's the
  75.     # identity of the virtual host to which the record
  76.     # applies.
  77.     #
  78.     ($vhost) = split (/\s/, $log_line);
  79.     #
  80.     # Normalize the virtual host name to all lowercase.
  81.     # If it's blank, the request was handled by the default
  82.     # server, so supply a default name.  This shouldn't
  83.     # happen, but caution rocks.
  84.     #
  85.     $vhost = lc ($vhost) or "access";
  86.     #
  87.     # If the log file for this virtual host isn't opened
  88.     # yet, do it now.
  89.     #
  90.     if (! $is_open{$vhost}) {
  91.         open $vhost, ">>${vhost}.log"
  92.             or die ("Can't open ${vhost}.log");
  93.         $is_open{$vhost} = 1;
  94.     }
  95.     #
  96.     # Strip off the first token (which may be null in the
  97.     # case of the default server), and write the edited
  98.     # record to the current log file.
  99.     #
  100.     $log_line =~ s/^\S*\s+//;
  101.     printf $vhost "%s", $log_line;
  102. }
  103. exit 0;
  104.